package com.site.wisdom_construction.controller.iotModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.iotModule.MonitorMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/21
 * @Description
 */
@Api(tags = "萤石云信息接口")
@RestController
@RequestMapping("MonitorMessageMonitorMessage")
@CrossOrigin
public class MonitorMessageController {
    @Autowired
    private MonitorMessageService monitorMessageService;

    @ApiOperation(value = "增加萤石云信息", notes = "测试数据:")
    @PostMapping("/insertMonitorMessage")
    public JsonResult insertMonitorMessage(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = monitorMessageService.insertMonitorMessage(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入萤石云信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入萤石云信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除萤石云信息", notes = "测试数据:")
    @PostMapping("/deleteMonitorMessage")
    public JsonResult deleteMonitorMessage(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = monitorMessageService.deleteMonitorMessage(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除萤石云信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除萤石云信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改萤石云信息", notes = "测试数据:")
    @PostMapping("/updateMonitorMessage")
    public JsonResult updateMonitorMessage(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = monitorMessageService.updateMonitorMessage(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改萤石云信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改萤石云信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "查询项目萤石云信息", notes = "测试数据:")
    @PostMapping("/findMonitorMessageByPorjectId")
    public OneDataResult findMonitorMessageByPorjectId(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(monitorMessageService.findMonitorMessageByPorjectId(map));
        return oneDataResult;
    }
}
